//
//  RTMPView.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/5/18.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation

enum RTMPStatus {
    case `default`
    case inloading
    case living
}

class RTMPView: MSView {
    
    var statusRtmp:RTMPStatus = .default {
        didSet {
            let type = Td.sh().cloud.hasLive ? "直播":"录制"
            var tx:String = ""
            switch statusRtmp {
            case .default:
                tx = "定制\(type)流服务"
            case .inloading:
                tx = "正在开启中.."
            case .living:
                tx = "\(type)中"
            }
            self.contLab.stringValue = tx
            let wid = tx.ga_width(font: 14)+20
            self.contLab.snp.updateConstraints { (make) in
                make.width.equalTo(wid)
            }
        }
    }
    
    override init(frame frameRect: NSRect) {
        super.init(frame: frameRect)
        self.setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI()  {
        self.addSubview(liveLab)
        liveLab.snp.makeConstraints { (make) in
            make.width.equalTo(40)
            make.left.equalToSuperview()
            make.centerY.equalToSuperview()
            make.height.equalTo(24)
        }
        
        self.addSubview(contLab)
        contLab.snp.makeConstraints { (make) in
            make.width.equalTo(120)
            make.left.equalTo(liveLab.snp.right)
            make.centerY.equalToSuperview()
            make.height.equalTo(24)
        }
    }
    
    lazy var liveLab: NSLabel = {
        let lab = NSLabel.label(title: "LIVE", textColor: color_gray(255), font: NSFont.systemFont(ofSize: 14))
        lab.backgroundColor = NSColor.red
        lab.alignment = .center
        return lab
    }()
    
    lazy var contLab: NSLabel = {
        let type = Td.sh().cloud.hasLive ? "直播":"推流"
        let lab = NSLabel.label(title: "定制\(type)流服务", textColor: color_gray(255), font: NSFont.systemFont(ofSize: 14))
        lab.backgroundColor = color_gray(40)
        lab.alignment = .center
        return lab
    }()
}
